﻿using System;
using System.Collections.Generic;
using System.Text;

namespace OliveChess
{

    public struct Move
    //class Move
    {
    
	    public int begin;
	    public int end;

        public char promotion;
        
        public Move(int square1, int square2)
        {
            begin = square1;
            end = square2;
            this.promotion = '0';
        }
        
	    public Move(int square1, int square2, char promotion) {
		    begin = square1;
		    end = square2;
	        this.promotion = promotion;
	    }
	
	    public Move(Move move) {
		    this.begin = move.begin;
		    this.end = move.end;
	        this.promotion = move.promotion;
	    }

        public Move(String move)
        {
            this.begin = Square.Get(move.Substring(0, 2));
            this.end = Square.Get(move.Substring(2, 2));
            if (move.Length == 5)
            {
                promotion = move[4];
            }
            else
            {
                promotion = '0';
            }
        }

	    public bool IsEqual(Move m) {
		    return ( (m.begin == begin) && (m.end == end) && (m.promotion == promotion));
	    }

        public static Move Null = new Move(128,128,'0');
        	
	    public override String ToString() {
            if (promotion != '0') return Square.ToString(begin) + Square.ToString(end) + promotion; 
            return Square.ToString(begin) + Square.ToString(end); 
	    }

        public static bool operator==(Move m1, Move m2){
            return (m1.begin==m2.begin) && (m1.end==m2.end) && (m1.promotion==m2.promotion);
        }

        public static bool operator!=(Move m1, Move m2)
        {
            return (m1.begin != m2.begin) || (m1.end != m2.end) || (m1.promotion != m2.promotion);
        }
        
    }

}
